<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.gzsz.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String user_Name = request.getParameter("user_Name");
    String user_Accuont = request.getParameter("user_Accuont");
    String user_Password = request.getParameter("user_Password");
    String user_Type = request.getParameter("user_Type");
    String phone_number = request.getParameter("phone_number");
    String email = request.getParameter("email");
    String gender = request.getParameter("gender");

    // 空值检查
//    if (Name == null ||Password == null || Role == null) {
//        out.println("参数不能为空，请检查表单数据。");
//    } else {
    try {
        DBUtil dbUtil = new DBUtil();
        // 构造带参数的 SQL 语句
        String sql = "INSERT INTO users(user_Name,user_Accuont, user_Password, user_Type,phone_number,email,gender) VALUES " +
                "('" + user_Name + "','" + user_Accuont + "', '" + user_Password + "', '" + user_Type + "', '" + phone_number + "', '" + email + "', '" + gender + "');";
        // 3. 创建预编译命令对象
//            String sql = "INSERT INTO users (name, gender, age, phone, user_account) VALUES (?, ?, ?, ?, ?)";
//            preparedStatement = connection.prepareStatement(sql);
//
//// 设置参数
//            preparedStatement.setString(1, name);
//            preparedStatement.setString(2, gender);
//            preparedStatement.setInt(3, Integer.parseInt(age));
//            preparedStatement.setString(4, phone);
//            preparedStatement.setString(5, number);
        // 执行插入操作
        int i = dbUtil.executeUpdateBySQL(sql);
        if (i > 0) {
            response.sendRedirect("user-addition.jsp");
        } else {
            out.println("插入失败");
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.println("发生错误：" + e.getMessage());
//        }
    }
%>
